class PromiseX {
  private callbacks: Array<Function> = []
  constructor(fn) {
    const resolve = () => {
      this.callbacks.forEach(callback => callback())
    }
    fn(resolve)
  }
  then(callback) {
    this.callbacks.push(callback)
  }
}
const promise = new PromiseX(function (resolve) {
  setTimeout(function () {
    resolve(100)
  }, 1000)
})
promise.then(() => console.log(1))
promise.then(() => console.log(2))
